/**
 * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.opsli.modulars.shop;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.opsli.api.base.result.ResultWrapper;
import org.opsli.api.web.shop.shopconfig.ShopConfigRestApi;
import org.opsli.api.wrapper.shop.shopconfig.ShopConfigModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 * 店铺配置 Controller
 *
 * @author 17607080935
 * @date 2024-10-12 17:57:15
 */
@Api(tags = ShopConfigRestApi.TITLEWECHATMINI)
@Slf4j
@RestController
@RequestMapping("/weMini/NotToken")
public class WeChatShopRestController{

    @Autowired
    ShopConfigRestApi shopConfigRestApi;
    /**
     * 最近店铺
     * @return ResultWrapper
     */
    @GetMapping("/listByDistance10")
    @ApiOperation(value = "获得单条店铺配置", notes = "获得单条店铺配置 - ID")
    public ResultWrapper<?> get(String lat,String lon,String id,String title) {

        if(id!=null){
            try {
                log.info("开始解义{}",id);
                id= URLDecoder.decode(id, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                log.info("解码失败{}",id);
            }
        }
        // 如果系统内部调用 则直接查数据库
        return ResultWrapper.getSuccessResultWrapper(shopConfigRestApi.listByDistance10(lat,lon,id,title).getData());
    }
}